package cn.fz.luck.saas.controller;

import cn.fz.luck.saas.bean.SysStatusEnum;
import cn.fz.luck.saas.bean.input.SysUserInputDTO;
import cn.fz.luck.saas.config.exception.ServerException;
import cn.fz.luck.saas.model.SysUser;
import cn.fz.luck.saas.service.SysUserService;
import cn.fz.luck.saas.util.DTOConvert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by zhuangqi on 17-7-6.
 */
@Controller
@RestController(value = "/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @PutMapping
    public ResponseEntity<?> update(@RequestBody SysUserInputDTO sysUserInputDTO) throws ServerException {
        SysUser sysUser = DTOConvert.change(SysUser.class,sysUserInputDTO);
        sysUserService.update(sysUser);
        return ResponseEntity.noContent().build();
    }

    @DeleteMapping
    public ResponseEntity<?> delete(@RequestParam String userId) throws ServerException {
        sysUserService.updateStatus(userId, SysStatusEnum.DISABLE);
        return ResponseEntity.noContent().build();
    }

}
